/**
 * @author Michael,Oct 17, 2012
 *
 */
package com.tm.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tm.enums.TaskStatusEnum;
import com.tm.pojo.Task;

/**
 * @author Michael
 *
 */
public class TaskDAO extends BaseHibernateDAO {

	public Task save(Task task){
		 super.save(task);
		 return task;
	}
	
	public void update(Task task){
		super.update(task);
	}
	
	public void saveOrUpdate(Task task){
		super.saveOrUpdate(task);
	}
	
	public Task findByName(String name){
		String hql = "from Task where taskName = :taskName and status <> :status and deleted = :deleted";
		Map params = new HashMap();
		params.put("taskName", name);
		params.put("status", TaskStatusEnum.CLOSED.getCodeDesc());
		params.put("deleted", false);
		return (Task)super.executeUniqueHQLQuery(params, hql);
	}
	
	public List<Task> listAll(){
		String hql = "from Task where deleted = :deleted and status <> :status order by createdTime, taskName";
		Map map = new HashMap();
		map.put("deleted", false);
		map.put("status", TaskStatusEnum.CLOSED.getCodeDesc());
		return (List)super.executeHQLQuerys(map, hql);
	}

}
